package perform.query.impl;

import java.lang.reflect.Field;
import java.sql.Connection;

import perform.exception.QueryException;
import perform.mappings.ClassMappings;
import perform.mappings.ManyToManyMapping;
import perform.query.AbstractQuery;
import perform.type.Type;

public class M2MInsertQuery extends AbstractQuery {

	public M2MInsertQuery(ManyToManyMapping mapping, Type source,
			Field sourceField, Type target, Connection connection)
			throws QueryException {
		super();
		try {
			query = mapping.getInsertQuery(sourceField);
			preparedStatement = connection.prepareStatement(query);
			setValue(1, ClassMappings.getIDField(source.getClass()).get(source));
			setValue(2, ClassMappings.getIDField(target.getClass()).get(target));
		} catch (Exception e) {
			throw new QueryException(e);
		}
	}

}
